package com.zzy.furns.web;

import com.zzy.furns.domain.Member;
import com.zzy.furns.service.MemberService;
import com.zzy.furns.service.impl.MemberServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {

    private MemberService memberService = new MemberServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        Member member = memberService.login(username, password);
        if (member == null){
            //用户名或密码错误，登陆失败，返回登陆界面重新登陆
            req.setAttribute("error","用户或密码错误");
            req.setAttribute("username",username);
            req.getRequestDispatcher("/views/member/login.jsp").forward(req,resp);
            return;
        }

        //登陆成功
        req.getRequestDispatcher("/views/member/login_ok.jsp").forward(req,resp);
    }
}
